<?php
class Util_log {
	//错误日志
	public static function error($locate, $msg) {
		$msg = " [ERROR] $msg";
		$url = LOG_ROOT."/err_log";
		if (! is_dir ( $url )) {
			mkdir ( $url,0777,true );
		}
		self::write ( $url."/err", $locate, $msg );
	}
	//行为记录日志
	public static function action_log($locate, $user_id, $msg) {
		$msg = " [LOG] $msg";
		$url = LOG_ROOT."/user_action_log/user_$user_id";
		if (! is_dir ( $url )) {
			mkdir ( $url,0777,true );
		}
		self::write ( "$url/{$user_id}_action", $locate, $msg );
	}
	//调式日志
	public static function debug($locate, $msg) {
		$msg = " [ERROR] $msg";
		$url = LOG_ROOT."/debug_log";
		if (! is_dir ( $url )) {
			mkdir ( $url,0777,true );
		}
		self::write ( $url."/debug", $locate, $msg );
	}
	
	//写入工具
	private static function write($logpath, $locate, $msg) {
		$outputMsg = "";
		
		$outputMsg = date ( '[Y-m-d H:i:s] ' );
		
		$outputMsg .= str_replace ( $_SERVER ["DOCUMENT_ROOT"], "", $locate );
		
		if (gettype ( $msg ) == "string")
			$outputMsg .= $msg;
		
		$outputMsg .= "\r\n";
		
		$logPathYMD = $logpath . "_" . date ( 'Ymd' ) . ".log";
		
		$fp = fopen ( $logPathYMD, "a" );
		fwrite ( $fp, $outputMsg );
		fclose ( $fp );
	}
}
?>